<?php
/**
 * Purpose of this class is an object containing all user related information
 */

require_once "Password.php";
require_once "HTMLable.php";
require_once "FormTempl.php";

class User extends HTMLable {
	public $name, $pass, $surname, $given, $nationality, $latitude, $longtitude,
	       $loggedIn;
	public $date_of_birth, $latitude_home, $longitude_home;
	
	public function __construct($user) {
		$this->name = $user['username'];
		$this->pass = $user['pass'];
		$this->surname = $user['surname'];
		$this->given = $user['given'];
		$this->nationality = $user['nationality'];
		$this->latitude = $user['latitude'];
		$this->longtitude = $user['longtitude'];
		
		$this->date_of_birth = $user['date_of_birth'];
		$this->latitude_home = $user['latitude_home'];
		$this->longitude_home = $user['longitude_home'];
		
		$this->loggedIn = false;
	}
	
	public function setLoggedIn($bool) {
		$this->loggedIn = $bool;
	}
	
	public function genHTML() {
		if ($this->loggedIn) {
			$this->html = "
			<div class=\"user private\">
				<ul class=\"personalInfo\">
					<li><h3><a href=\"user.php?u=".$this->name."\">".$this->name."</a></h3></li>
					<li><img src=\"img/person.png\" alt=\"Person:\" />".$this->given." ".$this->surname."</li>
					<li><img src=\"img/nationality.png\" alt=\"Nationality:\" />".$this->nationality."</li>
					<li><img src=\"img/globe.png\" alt=\"Location:\" />".$this->latitude.", ".$this->longtitude."</li>
				</ul>
				<ul class=\"userActions\">
					<li><img src=\"img/add.png\" alt=\"+\" /><a href=\"write.php?act=write\">Add blog post</a></li>
				</ul>
				<ul class=\"userLinks\">
					<li><img src=\"img/settings.png\" alt=\"\" /><a href=\"user.php?act=edit&u=".$this->name."\">Edit info</a></li>
					<li><img src=\"img/logout.png\" alt=\"\" /><a href=\"proc/proc_login.php?act=logout\">Logout</a></li>
				</ul>
				<hr class=\"clearer\" />
			</div>";
		} else {
			$this->html = "
		<div class=\"user public\">
			<h3>".$this->name."</h3>
			<ul class=\"personalInfo\">
				<li><img src=\"img/person.png\" alt=\"Person:\" />".$this->given." ".$this->surname."</li>
				<li><img src=\"img/nationality.png\" alt=\"Nationality:\" />".$this->nationality."</li>
				<li><img src=\"img/globe.png\" alt=\"Location:\" />".$this->latitude.", ".$this->longtitude."</li>";
		
			if ($date_of_birth != null)
				$this->html .= "<li><img src=\"img/globe.png\" alt=\"Location:\" />".$this->date_of_birth."</li>";
			if ($latitude_home != null && $longitude != null)
				$this->html .= "<li><img src=\"img/globe.png\" alt=\"Location:\" />".$this->latitude_home.", ".$this->longitude_home."</li>";
			
			$this->html .= "
			</ul>
			<hr class=\"clearer\" />
		</div>";
		}
	}
	
	public function editInfoHTML() {
		$form = new FormTempl("user", $this);
		return $form->getHTML();
	}
}
?>
